package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.table.NjTicketUserTableDef;
import com.dingreading.cloud.common.util.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.admin.entity.NjTicketUser;
import com.dingreading.cloud.admin.mapper.NjTicketUserMapper;
import com.dingreading.cloud.admin.service.NjTicketUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2025-01-03
 */
@Service
public class NjTicketUserServiceImpl extends BaseServiceImpl<NjTicketUserMapper, NjTicketUser, NjTicketUserTableDef> implements NjTicketUserService {

    @Override
    protected NjTicketUserTableDef getTable() {
        return NjTicketUserTableDef.njTicketUser;
    }

    @Override
    public Page<NjTicketUser> pageList(PageUtil pageUtil, String keyword, Integer ticketType, Integer permitStatus, Integer getStatus) {
        QueryCondition condition = QueryCondition.createEmpty();
        if (StringUtils.isNotBlank(keyword))
            condition.and(table.corpName.like(keyword)
                    .or(table.name.like(keyword))
                    .or(table.phone.like(keyword))
            );
        if (null != ticketType)
            condition.and(table.ticketType.eq(ticketType));
        if (null != permitStatus)
            condition.and(table.permitStatus.eq(permitStatus));
        if (null != getStatus)
            condition.and(table.getStatus.eq(getStatus));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.id.desc());

        return getMapper().paginate(Page.of(pageUtil.getPage(), pageUtil.getRows()), wrapper);
    }

    @Override
    public NjTicketUser getByUid(String uid) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.uid.eq(uid));
        return getMapper().selectOneByCondition(condition);
    }

    @Override
    public List<NjTicketUser> getByPhones(ArrayList<String> phones) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.phone.in(phones));
        return getMapper().selectListByCondition(condition);
    }

}
